import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int textFieldCount = 0;
  TextEditingController textFieldController = TextEditingController();
  int selectedButtonIndex = 0; // 添加新的变量

  void updateTextFieldContent(int index) {
    setState(() {
      if (index == 0) {
        textFieldController.text = '这是缺勤信息';
        textFieldCount = 0;
      } else if (index == 1) {
        textFieldController.text = '这是课程信息';
        textFieldCount = 1;
      } else if (index == 2) {
        textFieldController.text = '这是请假信息';
        textFieldCount = 2;
      }
      selectedButtonIndex = index; // 更新选中的按钮索引
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('ProfilePage'),
        ),
        body: Column(
          children: [
            Container(
              color: Colors.purple,
              padding: EdgeInsets.all(16),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    width: 80,
                    height: 80,
                    color: Colors.blue,
                    child: Center(
                      child: Icon(
                        Icons.person,
                        size: 40,
                        color: Colors.white,
                      ),
                    ),
                  ),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          '名字',
                          style: TextStyle(
                            fontSize: 22,
                            fontWeight: FontWeight.bold,
                            color: Colors.white,
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              color: Colors.white,
              padding: EdgeInsets.all(19),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      Expanded(
                        child: GestureDetector(
                          onTap: () {
                            updateTextFieldContent(0);
                          },
                          child: Container(
                            height: 50,
                            color: textFieldCount == 0
                                ? Colors.lightGreen
                                : Colors.transparent,
                            child: Center(
                              child: Text(
                                '缺勤数',
                                style: TextStyle(
                                  color: textFieldCount == 0
                                      ? Colors.white
                                      : Colors.black,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ),
                          ),
                        ),
                      ),
                      Expanded(
                        child: GestureDetector(
                          onTap: () {
                            updateTextFieldContent(1);
                          },
                          child: Container(
                            height: 50,
                            color: selectedButtonIndex == 1
                                ? Colors.lightGreen
                                : Colors.transparent,
                            child: Center(
                              child: Text(
                                '课程数',
                                style: TextStyle(
                                  color: selectedButtonIndex == 1
                                      ? Colors.white
                                      : Colors.black,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ),
                          ),
                        ),
                      ),
                      Expanded(
                        child: GestureDetector(
                          onTap: () {
                            updateTextFieldContent(2);
                          },
                          child: Container(
                            height: 50,
                            color: textFieldCount ==2
                                ? Colors.lightGreen
                                : Colors.transparent,
                            child: Center(
                              child: Text(
                                '请假数',
                                style: TextStyle(
                                  color: textFieldCount ==2
                                      ? Colors.white
                                      : Colors.black,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                  SizedBox(height: 25),
                  //for (int i = 0; i <= textFieldCount; i++)
                    Container(
                      height: 80,
                      decoration: BoxDecoration(
                        border: Border.all(
                          color: Colors.lightGreen,
                          width: 2.0,
                        ),
                      ),
                      child: TextFormField(
                        enabled: false,
                        controller: textFieldController,
                        textAlign: TextAlign.center,
                        decoration: InputDecoration(
                          border: InputBorder.none,
                          hintText: '这是缺勤信息',
                        ),
                      ),
                    ),
                ],
              ),
            ),
          ],
        ),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: 0,
          onTap: (int index) {},
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.message),
              label: '课表',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: '签到',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.person),
              label: '我的',
            ),
          ],
        ),
      ),
    );
  }
}